<template>
  <div class="cp-shape-title">
    <div class="cp-shape-title__shape"
         :class="{ square: shapeType === 'square', dot: shapeType === 'dot' }"
         :style="{
        backgroundColor: shapeHexColor,
        width: shapeSize,
        height: shapeSize,
      }" />
    <div class="cp-shape-title__text"
         :style="{ fontSize: titleSize, color: titleHexColor }">
      {{ text }}
    </div>

    <slot />
  </div>
</template>

<script>
export default {
  name: 'ymShapeTitle',
  props: {
    shapeType: {
      validator: function (value) {
        // 这个值必须匹配下列字符串中的一个
        return ['dot', 'square'].indexOf(value) !== -1
      },
      default: 'square',
    },
    shapeHexColor: {
      validator: function (value) {
        // 这个值必须匹配下列字符串中的一个
        const reg = /^#?([a-fA-F0-9]{6}|[a-fA-F0-9]{3})$/
        return reg.test(value.toString())
      },
      default: '#20222A',
    },
    shapeSize: {
      type: String,
      default: '10px',
    },
    titleSize: {
      type: String,
      default: '18px',
    },
    titleHexColor: {
      validator: function (value) {
        // 这个值必须匹配下列字符串中的一个
        const reg = /^#?([a-fA-F0-9]{6}|[a-fA-F0-9]{3})$/
        return reg.test(value.toString())
      },
      default: '#000000',
    },
    text: {
      type: String,
      default: 'title',
    },
  },
  data () {
    return {}
  },
}
</script>
<style lang="scss" scope>
.cp-shape-title {
  position: relative;
  display: flex;
  justify-content: flex-start;
  align-items: center;
  margin: 10px 0;
  &__shape {
    margin-right: 10px;
    box-shadow: border-box;
    &.dot {
      border-radius: 50%;
    }
  }
  &__text {
    height: 28px;
    line-height: 28px;
    font-family: PingFangSC-Medium, SourceHanSansCN-Medium, 'Microsoft YaHei',
      system-ui;
    font-weight: 500;
    letter-spacing: 2px;
  }
}
</style>
